#!/usr/bin/env python
# -*- coding:utf8 -*-
"""
Author : mafei
@Date   : 2019/12/02

"""

from mmonitor.models.mysql_db import db

class PeeweeConnectionMiddleware(object):
    def process_request(self, request):
        if db.is_closed():
            db.connect()

    def process_response(self, request, response):
        if not db.is_closed():
            db.close()
        return response